/*
 * ProxClone : Proximity Clone, a war of numbers
 * Copyright (C) 2011-2011 Edi Ermawan <edi.ermawan@gmail.Com>
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */
#ifndef _PLAY_STATE__
#define _PLAY_STATE__

#include <vector>
#include <time.h>


//#include "boost/shared_ptr.hpp"

#include "GameState.h" 

#include "GraphicUtils.h"
#include "HexaTile.h"
#include "HandCursor.h"
#include "Constant.h"
#include "AnimatedObject.h"

#include "TileAnimAlgorithm.h"
#include "TileAnimAlgorithm_A.h"

using namespace Game;

class PlayState:public GameState
{
public:
	PlayState();
	~PlayState();

	void OnEvent(SDL_Event* Event);
	bool OnInit(SDL_Surface* p_SurfDisplay);
	void OnLoop();
	void OnRender(SDL_Surface* p_SurfDisplay);
	void OnCleanup();
private:
	SDL_Surface* mImage1;
	SDL_Surface* mImage2;
	SDL_Surface* mImage3;
	SDL_Surface* mImage4;

	TileAnimAlgorithm* mTilesAnim;
	

	//boost::shared_ptr<SDL_Surface>mImage1;
	//boost::shared_ptr<SDL_Surface>mImage2;
	//boost::shared_ptr<SDL_Surface>mImage3;
	//boost::shared_ptr<SDL_Surface>mImage4;

	SDL_Surface* mImgGearBlue;
	SDL_Surface* mImgGearGreen;

	SDL_Surface* mImgBlue;
	SDL_Surface* mImgGreen;
	SDL_Surface* mDisplayPtr;

	

	std::vector<HexaTile*> HexaTiles;
	std::vector<HexaTile*>::iterator hexIter;

	
	int mPointedTile;
	float mXLineBorder[MAX_COL];//12=max X (column) 

	//Game::GameState* mGameState;
	bool mMouseUp;
	bool mMouseDown;
	int mGameTurn;
	int mThisGameTurn;
	int NeighBor[6];


	AnimatedObject* animObj;

	AnimatedObject* mGearBlueAnim;
	AnimatedObject* mGearGreenAnim;

	AnimatedObject* mNextGreenAnim;
	AnimatedObject* mNextBlueAnim;

	AnimatedObject* mButtonBack;
	AnimatedObject* mButtonSound;
	AnimatedObject* mButtonNew;
	AnimatedObject* mButtonConnect;

	AnimatedObject* mYouWin;
	AnimatedObject* mYouLose;
	AnimatedObject* mGameDraw;


	int mNClosedTile;
	int mIntroStop;
	int randvalue;

	int randValue_A[60];
	int randValue_B[60];
	
	int Index_RandValue_A;
	int Index_RandValue_B;

	bool mIsGameOver;

	void InitAnim(SDL_Surface* p_SurfDisplay);
	int SolveTargetTile(int newNumb);
	void GetNeighBor(int tileNumb,int neighbor_[]);

	void CreateHexaTiles(SDL_Surface* p_SurfDisplay);
	void CheckCollision(float x,float y);
	void CheckNeighBorTiles(int tileX);
	void CheckButtonClicked();
	void InitPlayState();
	void InitGamePlay();
	void CleanGamePlay();
};



#endif